package com.hk.servlet;

import com.alibaba.fastjson.JSONObject;
import com.hk.model.CompanyMessage;
import com.hk.model.Nav;
import com.hk.service.ICompanyMessageService;
import com.hk.service.INavService;
import com.hk.service.impl.CompanyMessageServiceImpl;
import com.hk.service.impl.NavServiceImpl;
import com.hk.utils.CharacterEncoding;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: zhe
 * @Date: 2021/6/23 14:29
 * @Statement: 页面公共头部和底部信息
 */
@WebServlet("/mutual")
public class MutualServlet extends HttpServlet {

    /**
     * 查询所有公共信息
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        CharacterEncoding.setCharacterEncodingResp(req,resp,"UTF-8");
//        查询所有导航信息
        INavService iNavService = new NavServiceImpl();
        List<Nav> navList = iNavService.findAll(-1, -1);
//        查询公司信息默认0启用
        ICompanyMessageService iCompanyMessageService = new CompanyMessageServiceImpl();
        List<CompanyMessage> companyMessageList = iCompanyMessageService.findAll(-1, -1);
        Map<String, Object> map = new HashMap<>();
        map.put("status",0);
        map.put("message","success");
        map.put("commpany",companyMessageList.get(0));
        map.put("navList",navList);
        String mapJSON = JSONObject.toJSONString(map);
        PrintWriter out = resp.getWriter();
        out.write(mapJSON);
        out.flush();
        out.close();
    }

}
